/**
 * 
 */
package com.contact.dao;

import java.util.List;

import com.contact.model.Contact;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * @author David Zheng
 *
 */
public class ContactDaoImpl extends HibernateDaoSupport implements ContactDao {
	
	public Contact loadById(int id) {
		return (Contact)getSession().load(Contact.class, id);
	}

	/* (non-Javadoc)
	 * @see com.contact.dao.ContactDao#load(java.lang.String)
	 */
	public List<Contact> load(String name) {
		Query query = getSession().createQuery("from Contact");
		query.setCacheable(true);
		List<Contact> list = (List<Contact>)query.list();
		
		return list;
		
	}

	/* (non-Javadoc)
	 * @see com.contact.dao.ContactDao#loadAll()
	 */
	public List<Contact> loadAllValidContacts() {
		Query query = getSession().createQuery("from Contact c where c.valid='1'");
		query.setCacheable(true);
		List<Contact> list = (List<Contact>)query.list();
		return list;
	}

}
